package com.cy.tree;

import java.util.ArrayList;

/**
 * @Author: cy
 * @Date: 2021/09/27/21:41
 * @Description:
 */

//判断一课二叉树是否为搜索二叉树
public class Demo4 {
    public static int preValue = Integer.MIN_VALUE;
    public static void main(String[] args) {

    }


    public static boolean isBST(Node head){
        if(head == null){
            return true;
        }
        boolean isLeftBst = isBST(head.left);  //判断左树是否为搜索二叉树
        if(!isLeftBst){     //如果左树不是搜索二叉树,那么这个树肯定不是搜索二叉树
            return false;
        }
        if(head.value <= preValue){
            return false;
        }else{
            preValue = head.value;
        }
        return isBST(head.right);
    }

}
